package com.threeman.mapswaypoints1;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.CursorJoiner.Result;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class WaypointOverly extends ItemizedOverlay
{
	
	private Context mContext;
	
	private ArrayList<MyOverlayItem> mOverlays = new ArrayList<MyOverlayItem>();
	
	private Drawable mDefaultMarker;
	
	public WaypointOverly(Drawable defaultMarker, Context context) {
		super(defaultMarker);
		mContext = context;
		mDefaultMarker = defaultMarker;
	}
	
	public void addOverlay(MyOverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	protected MyOverlayItem createItem(int i) {
		return mOverlays.get(i);
	}
	
	@Override
	public int size() {
		return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
		MyOverlayItem item = mOverlays.get(index);
		
		//showToastMessage(item.getName() + "\n" + item.getDescription() + "\n" + item.getAdress() + "\n" + item.getPOI());
		try
		{
			MapsWaypointsActivity parent = (MapsWaypointsActivity) mContext;
			
			parent.waypointEdit(item);
			
			return true;
		}
		catch(Exception ex)
		{
			showToastMessage(ex.toString());
		}
		return true;
	}
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		
        super.draw(canvas, mapView, shadow);                   
		boundCenterBottom(mDefaultMarker);
	}
	
	/*
	 * OTHER METHODS
	 */
	
	private void showToastMessage(String msg)
	{

	      Toast toast = Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);

	      toast.show();

	}
}
